package com.fastloan.mgt.verify.util;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author yanwe
 * createTime 2017-12-2017/12/8 10:59
 */
public class GetParam{

    private String name;

    private String value;

    private Map<String,String> paramMap = new HashMap<>();

    private GetParam() {
    }

    public static GetParam newBuilder(){
        return new GetParam();
    }

    public GetParam add(String name, String value){
        paramMap.put(name,value);
        return this;
    }

    public String toUrl(){
        if (paramMap.isEmpty()){
            return "";
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("?");
        String param = paramMap.entrySet().stream()
                .map(entry -> entry.getKey() + "=" + entry.getValue())
                .collect(Collectors.joining("&"));
        stringBuilder.append(param);
        return stringBuilder.toString();
    }
}
